package com.sync.syncmasterdata.customer.repository.biprep;

import com.sync.syncmasterdata.customer.entity.bip.BipIdocnTrastForCustomerEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 客户档案 相关 id映射表
 */
@Repository
public interface BipCustomerIdcontrastRepository extends JpaRepository<BipIdocnTrastForCustomerEntity,Integer> {

    /**
     * 查询客户id映射记录是否存在
     * 返回修改id
     * @param pk
     * @return
     */
    @Query(nativeQuery = true, value= "select * from xx_idcontrast where pk_bill=:pk and bill_type='customer'")
    BipIdocnTrastForCustomerEntity getTrastId(@Param(value = "pk") String pk);

    //插入客户记录
    @Transactional
    @Modifying
    @Query(nativeQuery = true, value= "INSERT INTO XX_IDCONTRAST (BILL_TYPE, DR, FILE_ID, ISDELETE, PK_BILL, PK_IDCONTRA, SRCTYPE, SUB_MARK, SUB_MARK_B, TS) VALUES ('customer', '0',:#{#entity.file_id} , NULL, :#{#entity.pk_bill}, :#{#entity.pk_idcontra}, '1', NULL, NULL, :#{#entity.ts})")
    Integer addCustomerEntityByCode(@Param(value = "entity") BipIdocnTrastForCustomerEntity entity);





}
